function verify() 
{
	document.getElementById("res").innerHTML = "Checking";
	reqObj = new XMLHttpRequest();
	reqObj.onreadystatechange = process;
	reqObj.open("POST", "./load.jsp?id="
			+ document.getElementById("username").value, true);
	reqObj.send(null);
}

function process() 
{
	if (reqObj.readyState == 4) 
	{
		document.getElementById("res").innerHTML = reqObj.responseText;
	}
}

function formValidation()
{
	var uid = document.registration.userid;
	var passid = document.registration.passid;
	var uname = document.registration.username;
	var uadd = document.registration.address;
	var ucountry = document.registration.country;
	var uemail = document.registration.email;
	var umsex = document.registration.msex;
	var ufsex = document.registration.fsex; 
	if(userid_validation(uid,5,12) &&
		validsex(umsex,ufsex) &&
		passid_validation(passid,7,12)  &&
		allLetter(uname) && 
		alphanumeric(uadd) &&
		countryselect(ucountry) &&
		ValidateEmail(uemail) )
	{
		return true;
	}
		
	 
	return  false;
}


function validsex(umsex,ufsex)  
{  
	x=0;  
	  
	if(umsex.checked)   
	{  
		x++;  
	} if(ufsex.checked)  
	{  
		x++;   
	}  
	if(x==0)  
	{  
		alert('Select Male/Female');  
		umsex.focus();  
	return false;  
	}  
	else  
	{  
		alert('Form Successfully Submitted');  
		window.location.reload() ;
		return true;
	}  
}  


 
 function userid_validation(uid,mx,my)
{
	var uid_len = uid.value.length;
	if (uid_len == 0 || uid_len >= my || uid_len < mx)
	{
		alert("User Id should not be empty / length be between "+mx+" to "+my);
		uid.focus();
		return false;
	}
	return true;
}
 
 
 function passid_validation(passid,mx,my)
 {
	 var passid_len = passid.value.length;
	 if (passid_len == 0 ||passid_len >= my || passid_len < mx)
	 {
		 alert("Password should not be empty / length be between "+mx+" to "+my);
		 passid.focus();
		 return false;
	  }
	 return true;
 }
             
 
 
 
 
 function allLetter(uname)  
 {   
	 var letters = /^[A-Za-z]+$/;  
	 if(uname.value.match(letters))  
	 {  
		 return true;  
	 }  
	 else  
	 {  
		 alert('Username must have alphabet characters only');  
		 uname.focus();  
		 return false;  
	 }  
 } 
 
 
 
 function alphanumeric(uadd)  
 {   
	 var letters = /^[0-9a-zA-Z]+$/;  
	 if(uadd.value.match(letters))  
	 {  
		 return true;  
	 }  
	 else  
	 {  
		 alert('User address must have alphanumeric characters only');  
		 uadd.focus();  
		 return false;  
	 }  
 }  
 
 
 
 function countryselect(ucountry)  
 {  
	 if(ucountry.value == "Default")  
	 {  
		 alert('Select your country from the list');  
		 ucountry.focus();  
		 return false;  
	 }  
	 else  
	 {  
		 return true;  
	 }  
 }  
 
 function ValidateEmail(uemail)  
 {  
	 var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
	 if(uemail.value.match(mailformat))  
	 {  
		 return true;  
	 }  
	 else  
	 {  
		 alert("You have entered an invalid email address!");  
		 uemail.focus();  
		 return false;  
	 }  
 }  
